<template>
  <erp-form-new-supplier
    v-model="tempValue"
    v-bind="$attrs"
    :form="tempForm"
    @value-change="handleModalValueChange"
    @update-id-field="handleModalUpdateField"
  />
</template>

<script>
import ErpFormNewSupplier from '@/components/erp/form/ErpFormNewSupplier';
/**
 * 客户颜色
 * @author maolin
 */
export default {
  name: "ErpTableNewSupplier",
  components: {
    ErpFormNewSupplier
  },
  model: {
    prop: "value",
    event: "value-change"
  },
  props: {
    /**
     * 表单对象
     * @public
     */
    form: {
      type: Object,
      default () {
        return {};
      }
    },
    /**
     * 默认值
     * @public
     */
    value: {
      type: [String, Number],
      default: null
    }
  },
  data () {
    return {
      tempValue: null,
      tempForm: null,
    };
  },
  watch: {
    value: {
      handler(value) {
        this.tempValue = value;
      },
      immediate: true
    },
    form: {
      handler(form) {
        this.tempForm = form;
      },
      immediate: true
    }
  },
  mounted() {
  },
  methods: {
    /**
     * 将值传递父组件
     * @param data
     * @public
     */
    handleModalValueChange (data) {
      /**
       * 将值传递父组件
       * @param data
       * @public
       */
      this.$emit('value-change', data);
    },
    /**
     * 将表单更新
     * @param data
     * @public
     */
    handleModalUpdateField (data) {
      if (this.tempForm) {
        let newForm = Object.assign(this.tempForm, data);
        this.$emit('update:form', newForm);
      }

    },
  }
};
</script>

<style scoped>

</style>
